package com.wb.fw;

/**
 * 逻辑地图坐标都不采用缩放，直接按base。
 * @author Administrator
 *
 */
public class WorldCamera implements IConstants {
	private static WorldCamera scamera;
	public static WorldCamera getInstance() {
		if (scamera == null) {
			scamera = new WorldCamera();
		}
		return scamera;
	}
	
	protected WorldCamera() {
		
	}
	
	float mpox, mpoy, mlastPox, mlastPoy, offsetPosx;
	int mcameraw,mcamerah,mtargetFocusX;
	WorldObject mtarget;
	public void setTarget(WorldObject target, int focusX) {
		mtarget = target;
		mcameraw = BASE_VERSION_SCREEN_WIDTH;
		mcamerah = BASE_VERSION_SCREEN_HEIGHT;
		mtargetFocusX = focusX;
		mpox = mtarget.mposx - mtargetFocusX;//-(mcameraw>>1);
	}
	
	public void resetCamera() {
		offsetPosx = 0;
		mlastPoy = 0;
		mlastPox = 0;
		mpox = 0;
		mpoy = 0;
	}
	
	public void update(float delta) {
		if (mtarget == null) {
			return;
		}
		mpox = mtarget.mposx - mtargetFocusX;//-(mcameraw>>1);
		mpoy = mtarget.mposy;//-(mcamerah>>1);
//		if (mpox < -(mcameraw>>1)) {
//			mpox = -(mcameraw>>1);
//		}
//		if (mpoy < 0) {
//			mpoy = 0;
//		}
		offsetPosx = (mpox - mlastPox);
		mlastPox = mpox;
		mlastPoy = mpoy;
	}
	
	/**
	 * 非缩放世界坐标
	 * @return
	 */
	public float getCameraPosx() {
		return mpox;
	}
	
	/**
	 * 获取实际屏幕像素，经过了缩放的。
	 * @return
	 */
	public float getFrameOffsetX() {
		return offsetPosx*Global.sScaleRate;
	}
}
